<?php
namespace app\common\model;

class MyCar extends Base
{
    protected $append = [
        'expire_time'
    ];

    public function getExpireTimeAttr($value,$data)
    {
        if($data['status'] == 1)
        {
            $expire = $data['end_time']-time();

            if($expire<=0)
                MyCar::where('my_id',$data['my_id'])->delete();

            $expire_time = time2second($expire);
        }else{
            $expire_time = '已过期';
        }
        return $expire_time;
    }

    public function getMyCar($map = [])
    {
        return $this->alias('m')
            ->join('car c','c.car_id = m.car_id','LEFT')
            ->where($map)
            ->field('m.is_use,m.end_time,m.update_time,c.img,c.thumbnail,c.car_name,c.price,m.status,c.car_id,m.my_id')
            ->order('m.update_time','desc')
            ->select();
    }
}